<template>
  <el-dialog
    :title="info.order_sn"
    :visible="historyVisible"
    class="main_dialog dialog840"
    @close="close"
    @open="open"
  >
    <div class="main_table mg-t-10">
      <el-table
        ref="multipleTable"
        height="400"
        :data="tableList"
        v-loading="listLoading"
        element-loading-text="加载中"
        fit
        highlight-current-row
      >
        <el-table-column label="打印时间" prop="print_time">
          <template slot-scope="{row}">
            {{ `${row.print_time} (第${row.print_num}次)` }}
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="print" />
        <el-table-column label="操作">
          <template slot-scope="{row}">
            <el-link class="mg-l-0" @click="print(row.id, row.uid, false)">打印</el-link>
            <el-link class="mg-l-0" @click="print(row.id, row.uid, true)">预览</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
     <div class="main_page boxdq">
        <div></div>
        <!-- 分页 -->
        <div class="main_page_r">
          <MainPagination
            :current-page="current.page"
            :page-sizes="[20, 30, 50, 100]"
            :page-size="current.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            background
            @size-change="changeSize"
            @current-change="changePage"
          />
        </div>
      </div>
  </el-dialog>
</template>

<script>
import { packApi } from "@/utils/public";
import {
  historyList,
} from "@/api/distribution/distributionList";
export default {
  props: {
    info: {
      type: Object,
      default: ()=> {}
    },
    historyVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      tableList: [],
      listLoading: false,
      current: {
        page: 1,
        pageSize: 20,
      },
      totalCount: 1,
    }
  },
  methods: {
    // 打开的回调
    open() {
      this.getList();
    },
    // 打印
    print(id,uid,preview) {
      this.$emit("histortPrint",{
        id,
        uid,
        preview,
        type: "historyPrint"
      })
    },
    getList() {
      this.listLoading = true;
      let data = packApi({
        id: this.info.id,
        uid: this.info.uid,
        ...this.current,
      });
      historyList(data).then(res=> {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.tableList = res.list.list;
          this.totalCount = res.list.total;
        }else {
          this.$message.error(res.errmsg);
        }
      })
    },
    // 分页
    changeSize(size){
      this.current.pageSize = size;
      this.getList();
    },
    changePage(page) {
      this.current.page = page;
      this.getList();
    },
    // 关闭
    close() {
      this.$emit('update:historyVisible',false);
      this.tableList = [];
      this.totalCount = 1;
      this.current.page = 1;
      this.current.pageSize = 20;
    },
  }
}
</script>

<style lang="scss" scoped>

</style>